/**
 * Copyright © 2009 Qasky. All rights reserved.
 *
 * 项目主程序
 *
 * @author Qi Zhang
 * @version 0.0.0 2018/05/27
 *
 * History:
 * (author, date, desc)
 * (Qi Zhang, 20180527, 添加注释)
 */
import Vue from 'vue'
import {router} from './router/index';
import store from './store/index';
import App from './app.vue';
import Es6Promise from 'es6-promise'
import pick from 'lodash.pick'
import 'babel-polyfill'
import Antd from 'ant-design-vue/es'
import 'ant-design-vue/dist/antd.less'
import './assets/iconfont/iconfont.css'
import './assets/color.less';
import moment from 'moment'
import 'moment/locale/zh-cn'
import Util from '@/libs/util';
import dict, {loadSysDicts, randerDictText} from '@/libs/dict';
import plLazy from 'module/plLazy'
import actions from './commontToken'
import QLibCrypto from './libs/QLibCrypto'
import {get, otherGetParams, post, uploadPost} from './libs/http'


import axios from 'axios';

Vue.component('pl-lazy', plLazy)

// 判断是否是ie9浏览器，如果是就执行针对ie9的一些兼容性处理

moment.locale('zh-cn')
Vue.use(Antd)

require('es6-promise').polyfill()
Es6Promise.polyfill()

if (document.documentMode && document.documentMode === 9) {
  Util.fixedProblemIE()
}

// 挂载全局
Vue.prototype.$axios = axios;
Vue.prototype.$uurl = 'http://127.0.0.1:18801';//本地访问智能密码钥匙
Vue.prototype.$pick = pick
Vue.prototype.hasPermission = Util.hasPermission;    // 权限方法
Vue.prototype.$loadSysDicts = loadSysDicts;    // 加载数据字典
Vue.prototype.randerDictText = randerDictText;
Vue.prototype.$dicts = dict;
Vue.prototype.$post = post
Vue.prototype.$get = get
Vue.prototype.$uploadPost = uploadPost
Vue.prototype.$otherGetParams = otherGetParams
Vue.prototype.$api = process.env.NODE_ENV === 'development'?'/api':''    //本地使用需要添加'/api'，上传服务器为''
const instance = new Vue({
  render: h => h(App),
  router: router,
  store: store,
    data: function () {
        return {
            role_id: 111,
            qsLib: '',
            qsBackData: {},
            userKey: {
                puk: '',
                signData: ''
            },
            authType:'pwd'
        }
    },
    methods: {
        getSocketResult(e) {
            let _this = this
            _this.qsBackData = e
            store.dispatch('setGlobalUserKey', _this.qsBackData)
            _this.changeQsLibAll()
            if (e.code === 0) {
                if (e.optWeb === 2) {
                    _this.$message.warning(e.message)
                }  else if (e.optWeb === 113) {
                    _this.userKey.puk = e.data
                    //下发公钥
                } else if (e.optWeb === 114) {
                    _this.userKey.signData = e.data
                    //下发签名
                } else if (e.optWeb === 115) {
                    _this.$message.success(e.message)
                }
            } else {
                //_this.$message.warning (e.message)
            }
        },
        changeQsLibAll() {
            actions.setGlobalState({
                qsLibAll: this.qsLib,
                qsBackData: this.qsBackData
            })
        }
    },
    created() {
        let _this = this
        _this.$get ('loadSystemSrvName').then (res => {
            if (res.code === 0) {
                if(res.data.authType !== undefined){
                    _this.authType = res.data.authType
                }else{
                    _this.authType = false
                }
                store.dispatch('setAuthType', _this.authType)
            } else {
                _this.$message.warning (res.message)
            }
        }).catch(e=>{
            _this.msg = "当前登录页面失效，稍后将重新加载...";
        })
    },
    mounted() {
    }
}).$mount('#mainApp')
// 定义loader方法，loading改变时，将变量赋值给App.vue的data中的isLoading
function loader (loading) {
  if (instance && instance.$children) {
    // instance.$children[0] 是App.vue，此时直接改动App.vue的isLoading
    instance.$children[0].isLoading = loading
  }
}





